package cn.tedu.superscholarstore.controller;

import cn.tedu.superscholarstore.mapper.FavoritesMapper;
import cn.tedu.superscholarstore.pojo.vo.FavoritesVo;
import cn.tedu.superscholarstore.pojo.vo.UserVO;
import cn.tedu.superscholarstore.service.FavoritesService;
import cn.tedu.superscholarstore.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpSession;
import java.util.List;
@Api(tags = "收藏管理模块")
@Slf4j
@RequestMapping("/favorites")
@RestController
public class FavoritesController {

    @Autowired
    FavoritesService service;

    public FavoritesController() {
        log.debug("创建业务处理对象: FavoritesController");
    }

    @ApiOperation("获取收藏列表")
    @ApiOperationSupport(order = 500)
    @GetMapping("")
    public JsonResult<List<FavoritesVo>> select(@ApiIgnore HttpSession session){
        log.debug("开始处理[获取收藏列表]请求,参数为{}",session);
        List<FavoritesVo> list = service.list(session);
        return JsonResult.ok(list);
    }

    @ApiOperation("删除收藏")
    @ApiOperationSupport(order = 300)
    @GetMapping("/delete")
    public JsonResult<Void> deleteById(int id){
        service.deleteById(id);
        return JsonResult.ok();
    }

    @ApiOperation("统计收藏数量")
    @ApiOperationSupport(order = 501)
    @GetMapping("/count")
    public JsonResult<Integer> countByUserId(@ApiIgnore HttpSession session){
        log.debug("开始处理[统计收藏数量]请求,参数为{}",session);
        Integer integer = service.countByUserId(session);
        return JsonResult.ok(integer);
    }

    @ApiOperation("分页查询收藏")
    @ApiOperationSupport(order = 502)
    @GetMapping("/select")
    public JsonResult<List<FavoritesVo>> selectByLim(@ApiIgnore int index,@ApiIgnore HttpSession session){
        log.debug("开始处理[分页查询收藏]请求,参数为{}{}",index,session);
        List<FavoritesVo> favoritesVos = service.selectByLim(index, session);
        return JsonResult.ok(favoritesVos);
    }
}
